<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-yellow sidebar-mini">

<section class="content-header">
    <h1>工艺卡接收</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label for="query-proCode">项目编号</label>
                                    <input id="query-proCode" type="text" name="proCode" class="form-control"
                                           placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label for="query-proName">项目名称</label>
                                    <input id="query-proName" type="text" name="proName" class="form-control"
                                           placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label for="query-malType">类型</label>
                                    <select id="query-malType" class="form-control" name="special">
                                        <option value="" selected>请选择</option>
                                        <option th:each="type : ${special}" th:value="${type.name}"
                                                th:text="${type.name}"></option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-part">部分</label>
                                    <input id="query-part" type="text" name="part" class="form-control"
                                           placeholder="请输入部分">
                                </div>
                                <!--                                <div class="form-group">-->
                                <!--                                    <label for="query-sheetType">单据类型</label>-->
                                <!--                                    <select id="query-sheetType" class="form-control" name="prodChange">-->
                                <!--                                        <option value="" selected>请选择</option>-->
                                <!--                                        <option value="0">正常单据</option>-->
                                <!--                                        <option value="1">变更单据</option>-->
                                <!--                                    </select>-->
                                <!--                                </div>-->
                                <div class="form-group">
                                    <label for="query-status">接收状态</label>
                                    <select id="query-status" class="form-control" name="recStatus">
                                        <option value="0" selected>未接收</option>
                                        <option value="1">已接收</option>
                                    </select>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search"
                                        onclick="js.table.search(table)">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    let table, sheetType = ['', '正常单据', '变更单据'];

    $(function () {

        // /** 马永峰版本 加载列表 */
        // table = js.table.init({
        //     url: ctx + "tecard/list",
        //     showExport: false,
        //     columns: [
        //         {
        //             title: '序号', field: 'id', width: '50',
        //             formatter: function (value, row, index) {
        //                 return index + 1;
        //             }
        //         },
        //         {title: "项目编号", field: 'prodNo',
        //             formatter:function (value,row){
        //                 if(value){
        //                     return '<span>'+value+'</span>';
        //                 }else{
        //                     return '<span>'+row.proCode+'</span>';
        //
        //                 }
        //             }
        //         },
        //         {title: "项目名称", field: 'proName',width:'250px'},
        //         {title: "项目数量", field: 'proNum'},
        //         {title: "类型", field: 'special'},
        //         {title: "部分", field: 'part'},
        //         {title: "创建科室", field: 'deptName'},
        //         {title: "单据类型", field: 'prodChange',
        //             formatter: function (value) {
        //                 return value == 0 ? '正常单据' : '变更单据';
        //             }
        //         },
        //         {title: "接收状态", field: 'recStatus',
        //             formatter: function (value) {
        //                 if (value === 0) {
        //                     return '<span class="badge label-inverse">未接收</span>';
        //                 } else if (value === 1) {
        //                     return '<span class="badge label-warning">已接收</span>';
        //                 }
        //             }
        //         },
        //         {title: "接收人", field: 'recName'},
        //         {title: "接收日期", field: 'recTime',width:'100px'},
        //
        //         {title: "操作",
        //             formatter: function (value, row) {
        //                 let actions = [];
        //                 if(row.recStatus==0 && hasP("data:proCardSign:sign")){
        //                     actions.push('<a class="btn btn-xs"  style="background-color: orangered;color: white" ' + 'onclick="receiveCard('+js.jsonStringify(row)+')"> 接收</a> ');
        //                     actions.push('<a class="btn btn-info btn-xs" target="_blank" onclick="selectMakeDetail('+js.jsonStringify(row)+')">查看</a> ');
        //                 }else if(row.recStatus==1 && hasP("data:proCardSign:sign")){
        //                     actions.push('<a class="btn btn-info btn-xs" target="_blank" onclick="selectMakeDetail('+js.jsonStringify(row)+')">查看</a> ');
        //                 }
        //                 return actions.join('');
        //             }
        //         }
        //     ]
        // });

        /** 因变更需求未满足而修改 加载列表 */
        table = js.table.init({
            url: ctx + "tecard/listGroupBy",
            showExport: false,
            columns: [
                {
                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {
                    title: "项目编号", field: 'prodNo',
                    formatter: function (value, row) {
                        if (value) {
                            return '<span>' + value + '</span>';
                        } else {
                            return '<span>' + row.proCode + '</span>';

                        }
                    }
                },
                {title: "项目名称", field: 'proName', width: '250px'},
                {title: "项目数量", field: 'proNum'},
                {title: "类型", field: 'special'},
                {title: "部分", field: 'part'},
                // {title: "单据类型", field: 'prodChange',
                //     formatter: function (value) {
                //         return value == 0 ? '正常单据' : '变更单据';
                //     }
                // },
                {
                    title: "接收状态", field: 'recStatus',
                    formatter: function (value) {
                        if (value === 0) {
                            return '<span class="badge label-inverse">未接收</span>';
                        } else if (value === 1) {
                            return '<span class="badge label-success">已接收</span>';
                        }
                    }
                },
                {
                    title: "操作",
                    formatter: function (value, row) {
                        let actions = [];
                        if (row.recStatus == 0 && hasP("data:proCardSign:sign")) {
                            actions.push('<a class="btn btn-xs"  style="background-color: orangered;color: white" ' + 'onclick="receiveCard(' + js.jsonStringify(row) + ')"> 接收</a> ');
                            actions.push('<a class="btn btn-info btn-xs" target="_blank" onclick="selectMakeDetail(' + js.jsonStringify(row) + ')">查看</a> ');
                        } else if (row.recStatus == 1 && hasP("data:proCardSign:sign")) {
                            actions.push('<a class="btn btn-info btn-xs" target="_blank" onclick="selectMakeDetail(' + js.jsonStringify(row) + ')">查看</a> ');
                        }
                        return actions.join('');
                    }
                }
            ]
        });
    });

    /** 查询该项目下专业下部分下的工艺卡*/
    function selectMakeDetail(row) {
        window.open(ctx + 'tecard/jump?proCode=' + row.proCode + '&special='
            + row.special + '&part=' + row.part + '&recStatus=' + row.recStatus + '&id=' + row.id);
    }

    /** 工艺卡接收功能*/
    function receiveCard(row) {
        js.post({
            url: ctx + "tecard/cardReceive",
            async: false,
            data: {tecards: JSON.stringify(row)},
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table)
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });
    }
</script>
</body>
</html>
